package com.skyjing.rvdadapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding


abstract class MultiItemCommonAdapter<T, V : ViewDataBinding>(
    context: Context, datas: List<T>,
    private var mMultiItemTypeSupport: MultiItemTypeSupport<T>
) : CommonAdapter<T, V>(context, -1, datas) {

    override fun getItemViewType(position: Int): Int {
        return if (mDatas.isNotEmpty()) mMultiItemTypeSupport.getItemViewType(position, mDatas[position])
        else NO_DATA
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<V> {
        val layoutId = mMultiItemTypeSupport.getLayoutId(viewType)

        val v = DataBindingUtil.inflate<V>(LayoutInflater.from(mContext), layoutId, parent, false)
        return ViewHolder(v)
    }
}
